package com.lzy.webapi.controller;

import com.lzy.framework.core.ensure.Ensure;
import com.lzy.framework.core.output.Result;
import com.lzy.webapi.component.UserToken;
import com.lzy.webapi.facade.WorkProgressFacade;
import com.lzy.webapi.response.ProgressClassifyResponse;
import com.lzy.webapi.response.WorkProgressResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**业绩进度查询接口
 * Created by WIN7 on 2017/12/13.
 */
@Controller
@RequestMapping("api/progress")
public class WorkProgressController extends BaseController{
    private static final Logger LOGGER = LoggerFactory
            .getLogger(WorkProgressController.class);

    @Autowired
    WorkProgressFacade workProgressFacade;

    /**
     * 获取分类list
//     * @param token
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public @ResponseBody Result getProgressClassifyList(@RequestHeader("token") String token) {
        UserToken ut = isLogin(token);
        Ensure.that(ut).isNotNull("01000006");
        List<ProgressClassifyResponse> classifyResponseList = workProgressFacade.getProgressClassifyList(ut.getUserId());
        if(classifyResponseList != null){
            return new Result(classifyResponseList);
        }
        return new Result();
    }

    /**
     * 获取业务增员信息
     * @return
     */
    @RequestMapping(value = "/detail/{id}", method = RequestMethod.GET)
    public @ResponseBody Result getProgressClassifyDetail(@RequestHeader("token") String token,@PathVariable("id") Long classifyId) {
        UserToken ut = isLogin(token);
        Ensure.that(ut).isNotNull("01000006");
        WorkProgressResponse workProgressResponse = workProgressFacade.getProgressClassifyDetail(ut.getUserId(),classifyId);
        if(workProgressResponse != null){
            return new Result(workProgressResponse);
        }
        return new Result();
    }


}
